<?php

class Models_Base {
//	protected $registry;
//	protected $db;
	protected $dbh;
	protected $counter;
	
	function __construct($registry = null) {
		
//		if(empty($registry))
//			die("Can't find $registry");
//$registry['debug']->warn( $registry['dbh'] );			
//		$this->registry = new Registry; //$registry;
//		$db = new ();
		$this->dbh = DB_Class_PDO::getInstance();//$registry['dbh'];
		
//		print_r($this->dbh)
	}
	
	function getRow($sql,$args = null) {
		$sth = $this->dbh->prepare($sql);
		
		if($args)
			$sth->execute($args);
		else 
			$sth->execute();

		return $sth->fetchObject();
	}
	
	function getAll($sql,$args = null) {
		$sth = $this->dbh->prepare($sql);
		
		if($args)
			$sth->execute($args);
		else
			$sth->execute();
		
		while($row = $sth->fetchObject()) {
			$out[] = $row;
		}		
		
		return $out;
	}
	
	
	
	
	function insertRow($sql,$args) {
		$sth = $this->dbh->prepare($sql);
		$sth->execute($args);
		
		return $this->dbh->lastInsertId();
	}
	
	
	function saveRow($sql,$args) {
		$sth = $this->dbh->prepare($sql);
		return $sth->execute($args);		
	}
	
	function execute($sql,$args=null) {
		$sth = $this->dbh->prepare($sql);
		
		if($args)
			return $sth->execute($args);
		else
			return $sth->execute();
	}
    
    function doExecute($sql,$args=null) {
        $sth = $this->dbh->prepare($sql);
        
        if($args)
            return $sth->execute($args);
        else
            return $sth->execute();        
    }
} 

?>
